<template>
<div>
  <h1>添加</h1>
  <p><input type="text" v-model="form.name">姓名</p>
  <button @click="add">添加</button>

  <table>
    <tr>
      <td>编号</td>
      <td>姓名</td>
      <td>操作</td>
    </tr>
    <tr v-for="i in list">
      <td>{{i.id}}</td>
      <td>{{i.name}}</td>
      <td>
        <router-link :to="{path:'/put_1',query:{id:i.id}}">修改</router-link>
        <button @click="del(i.id)">删除</button>
      </td>
    </tr>
  </table>


</div>
</template>

<script>
export default {
  name: "cate",
  data(){
    return{
      form:{},
      list:[]
    }
  },
  methods: {
    add() {
      this.$axios.post('http://127.0.0.1:5000/add', this.form)
        .then(i => {
          if (i.data.code == 200) {
            alert("添加成功")
            this.show()
          }
        })
    },
    show() {
      this.$axios.get('http://127.0.0.1:5000/add')
        .then(c => {
          this.list = c.data.list
        })
    },
    del(id) {
      this.$axios.delete('http://127.0.0.1:5000/add?id='+id)
      if (i.data.code == 200) {
        alert("修改成功")
        this.show()
      }
    }
    },
    mounted() {
      this.show()
    }

}
</script>

<style scoped>

</style>
